package exception;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 异常处理机制在IO操作中的应用
 */
public class FinallyDemo1 {
    public static void main(String[] args) {

        System.out.println("程序开始了...");
        FileOutputStream fos = null;
        try{
            fos=new FileOutputStream("./a/b/fos.txt");
        }catch(IOException I){
            System.out.println("出错了并解决了");
        }finally{
            try {
                fos.close();
            } catch (Exception e) {
                System.out.println("关闭异常");
            }
        }
        System.out.println("程序结束了...");

        /*
        //自动关闭特性是编译期认可的,编码编译后后跟上面编码一样;
        //在try()中定义的内容最终会被编译期改为finally中调用close()关闭操作;
        System.out.println("程序开始了");
        try(FileOutputStream fos = new FileOutputStream("fos.txt")){
            fos.write(1);
        }catch (IOException e){
            System.out.println("出错了并解决");
        }
         */


    }
}
